<?php

namespace app\api\server\music;

use app\api\model\music\MusicSelectedPackDetailApiModel;
use app\api\model\music\MusicSelectedPackApiModel;
use app\admin\ServerBase;
use app\api\model\music\MusicSelectedPackTypeApiModel;
use app\logic\single\GoodsSingle;
use think\db\exception\DbException;
use think\facade\Db;
use think\Request;

class MusicSelectedPackServer extends ServerBase
{
    protected $model;
    protected $request;
    /**
     * @var mixed
     */
    protected $param;
    /**
     * @var mixed
     */
    protected $validate;
    /**
     * @var MusicSelectedPackDetailApiModel
     */
    private $detailModel;
    /**
     * @var MusicSelectedPackTypeApiModel
     */
    private $typeModel;

    function __construct( Request $request)
    {
        //$this->checkAuth();
        $this->request=$request;
        $this->param=$request->param();
        $this->model=new MusicSelectedPackApiModel();
        $this->detailModel = new MusicSelectedPackDetailApiModel();
        $this->typeModel = new MusicSelectedPackTypeApiModel();
    }

    function getType(){
        $list = $this->typeModel->where('status',1)->field('id,title')
            ->order('sort desc,id desc')->select();
        $this->getMessageCode('adminMessage.success.select',2);
        return $list;
    }
    function getList(){
        [$page,$limit] = $this->getPage($this->param);
        $field='id,type_id,title,img,price,original_price,play_num,sale';
        $where['status'] =1 ;
        [$list,$count] = $this->model->getApiList($this->param,$where,$field,$page,$limit);
        $result['data']=$list;
        $result['count']=$count;
        $this->getMessageCode('adminMessage.success.select',2);
        return $result;
    }

    function getDetail(){
        $id =  $this->request->param('id');
        $info = $this->model->getDetail($id,'id,title,type_id,img,price,sale,original_price,play_num');
        if(empty($info)){
            $this->getMessageCode('code_common.not_find',1);
            return false;
        }
        $info['is_collection'] = GoodsSingle::getInstance()->isCollection($id,40);
        $info['is_have'] = GoodsSingle::getInstance()->isHave($info['id'],40,$this->request->user_id);
        $this->getMessageCode('adminMessage.success.select',2);
        return $info;
    }
}